package com.snackshop.controller;

import com.snackshop.pojo.model.User;
import com.snackshop.pojo.vo.R;
import com.snackshop.pojo.vo.RegisterVO;
import com.snackshop.pojo.vo.ResponseState;
import com.snackshop.service.RegisterService;
import com.snackshop.service.UserService;
import lombok.extern.java.Log;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Log
public class RegisterController {
    @Autowired
    private RegisterService registerService;

    @RequestMapping("/register")
    public R register(RegisterVO registerVO){
        log.info(registerVO.toString());
        User user = new User();
        BeanUtils.copyProperties(registerVO,user);
        Boolean register = registerService.register(user);
        if (register) {
            return R.RESULT(ResponseState.SUCCESS);
        }else {
            return R.RESULT(ResponseState.USEREXSITS);
        }
    }
}
